//
//  NewsDetailVC.m
//  WSLAPP
//
//  Created by 梁森 on 2020/7/23.
//  Copyright © 2020 WSL. All rights reserved.
//

#import "NewsDetailVC.h"

#import "Masonry.h"

@implementation NewsDetailVC

- (void)setUpUI{
    [super setUpUI];
    self.view.backgroundColor = [UIColor orangeColor];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"后退" style:UIBarButtonItemStyleDone target:self action:@selector(goBack)];
    UIBarButtonItem *forwardItem = [[UIBarButtonItem alloc] initWithTitle:@"前进" style:UIBarButtonItemStyleDone target:self action:@selector(goForward)];
    UIBarButtonItem *fontItem = [[UIBarButtonItem alloc] initWithTitle:@"字体" style:UIBarButtonItemStyleDone target:self action:@selector(changSize)];
    self.navigationItem.rightBarButtonItems = @[backItem,forwardItem,fontItem];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    CGFloat y = [UIApplication sharedApplication].statusBarFrame.size.height + 44;
    [self.webView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(y);
    }];
}
-(void)goBack{
    [self.webView goBack];
}
-(void)goForward{
    [self.webView goForward];
}
- (void)changSize{
    static int i = 20;
    i = i+20;
    if (i >= 100) {
        i = 20;
    }
    NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",i];
    [self.webView evaluateJavaScript:jsString completionHandler:^(id _Nullable objc, NSError * _Nullable error) {
        
    }];
}

@end
